package Offer.offer2017;

/**
 * 奇数位于偶数前面
 * Created by 雷文康 on 2017/12/31.
 */
public class Test14 {
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        adjustArray(array);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
    }
    public static void adjustArray(int[] array){
        if (array == null || array.length == 0){
            return;
        }
        int start = 0;
        int end = array.length -1;
        while (start < end){
            while (start < end && ((array[start] & 1) == 1)){
                    start++;
            }
            while (start < end && ((array[end] & 1) == 0)){
                end--;
            }
            if (start < end){
                int temp = array[start];
                array[start] = array[end];
                array[end] = temp;
            }
        }
    }
}
